package tcards.android;

import models.Kind;
import models.Status;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class KindChooser extends LinearLayout {
	private Status mStatus;
	private RadioGroup mKind;
	
	public KindChooser(Context context) {
		this(context, null, 0);
	}

	public KindChooser(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public KindChooser(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		LayoutInflater li = LayoutInflater.from(context);
		addView(li.inflate(R.layout.kind_chooser, this, false));
		Button okButton = (Button) findViewById(R.id.okButton);
		okButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				TcardsAndroidActivity activity = (TcardsAndroidActivity) getContext();
				activity.showEditPage(getChosenKind(), mStatus);
			}
		});
		mKind = (RadioGroup) findViewById(R.id.kindRadioGroup);
		for (int i = 0; i < mKind.getChildCount(); ++i) {
			RadioButton radio = (RadioButton) mKind.getChildAt(i);
			radio.setTextColor(TcardButton.getColorForKind(i));
		}
	}

	public Kind getChosenKind() {		
		switch (mKind.getCheckedRadioButtonId()) {
		case R.id.handCrewsChoice:
			return Kind.HandCrews;
		case R.id.enginesChoice:
			return Kind.Engines;
		case R.id.helicoptersChoice:
			return Kind.Helicopters;
		case R.id.personnelChoice:
			return Kind.Personnel;
		case R.id.aircraftChoice:
			return Kind.Aircraft;
		case R.id.dozersChoice:
			return Kind.HeavyEquipment;
		case R.id.miscChoice:
			return Kind.Misc;
		case R.id.genericChoice:
			return Kind.Generic;
		default:
			throw new RuntimeException("No choice made!");
		}
	}
	
	public void setStatus(Status status) {
		mStatus = status;
	}
	
	public Status getStatus() {
		return mStatus;
	}
}